package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.Video;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by liux on 2017/3/29.
 */

public class VideoAdapter extends BaseAdapter {
    private Context context;
    private List<Video> videos;

    public VideoAdapter(Context context, List<Video> videos) {
        this.context = context;
        this.videos = videos;
    }

    @Override
    public int getCount() {
        return videos.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null || convertView.getTag() == null) {
            convertView = LayoutInflater.from(context)
                    .inflate(R.layout.item_video, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Video video = videos.get(position);
        holder.addressTv.setText(video.getName());
        holder.deviceTv.setText(video.getName());
        if (video.getIsOnline() == 1) {
            holder.videoState.setImageResource(R.mipmap.video_online);
        } else {
            holder.videoState.setImageResource(R.mipmap.video_close);
        }
        return convertView;
    }


    static class ViewHolder {
        @BindView(R.id.video_state)
        ImageView videoState;
        @BindView(R.id.device_tv)
        HXTextView deviceTv;
        @BindView(R.id.collect_iv)
        ImageView collectIv;
        @BindView(R.id.address_tv)
        HXTextView addressTv;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
